package com.way.v1.service;

import com.way.v1.*;

/**
 * @author 魏彪
 */
public class MemberService {

    public void login(String loginName, String loginPass) {
//        if ("".equals(loginName) || "".equals(loginPass)) {
//            System.out.println("用户名和密码校验成功，可以往下执行");
//            return;
//        }
//
//        Member member = checkExists(loginName, loginPass);
//        if (null == member) {
//            System.out.println("用户不存在");
//            return;
//        }
//
//        System.out.println("登陆成功");
//
//        if (!"管理员".equals(member.getRoleName())) {
//            System.out.println("您不是管理员，没有操作权限");
//            return;
//        }
//        System.out.println("允许操作");
        Handler validateHandler = new ValidateHandler();
        Handler loginHandler = new LoginHandler();
        Handler authHandler = new AuthHandler();
        validateHandler.setChain(loginHandler);
        loginHandler.setChain(authHandler);

        validateHandler.handle(new Member(loginName, loginPass));
    }

    private Member checkExists(String loginName, String loginPass) {
        Member member = new Member(loginName, loginPass);
        member.setRoleName("管理员");
        return member;
    }

    public static void main(String[] args) {
        MemberService service = new MemberService();
        service.login("tom", "666");
    }
}
